Scaling: Remove Instances

Objective#

  • Replace explicit EC2 instances with Auto Scaling.

Steps#

  • Remove Instance and Instance2.

Removing the explicit instances#

Now that our new ASG instances are up and are serving requests through our load balancer, we can safely remove our explicit instances without causing any disruption. To do so, we just need to remove every reference to them from our main.yml script, and redeploy:

  • The entire Instance resource.
  • The entire Instance2 resource.
  • The entire Targets property from the LoadBalancerTargetGroup resource.
  • The Ec2TagFilters property from the StagingDeploymentGroup resource.
  • The InstanceEndpoint and InstanceEndpoint2 outputs.

Now, let’s redeploy our infrastructure by running deploy-infra.sh.

terminal

If we hit the load balancer endpoint now, we should see our traffic split between the two instances in our ASG. The other two instances have been terminated.

terminal

It’s time to checkpoint all our changes and push them to GitHub.

terminal

Note: All the code has been already added and we are pushing it on our repository as well.

Please provide values for the following:
username
Not Specified...
AWS_ACCESS_KEY_ID
Not Specified...
AWS_SECRET_ACCESS_KEY
Not Specified...
AWS_REGION
us-east-1
Github_Token
Not Specified...
/
server.js
main.yml
github.sh
setup.yml
deploy-infra.sh
stop-service.sh
start-service.sh
buildspec.yml
appspec.yml

Adding capacity in a pinch is much easier now. From the Auto Scaling console (FIGURE 1), you can select your ASG (FIGURE 2) and edit the desired capacity setting (FIGURE 3). The number of EC2 instances will automatically reflect your desired capacity within a few seconds.

NOTE: All these figures are shown below.

Auto Scaling Groups (FIGURE 1)
Auto Scaling Groups (FIGURE 1)
Auto Scaling Details (FIGURE 2)
Auto Scaling Details (FIGURE 2)
Auto Scaling Edit Group Size (FIGURE 3)
Auto Scaling Edit Group Size (FIGURE 3)

In order to get a pictorial view of our developed cloudformation stack so far, below is the design view which shows the resources we created and their relationships.

Add an Auto Scaling Group
Add an Auto Scaling Group

In the next lesson, we will create separate environments for staging and production.

Scaling: Add an Auto Scaling Group
Production: Add Stack Name to our Application
Mark as Completed
Report an Issue